---
title: "Main Figures and Tables"
author: "Kaylyn Jackson Schiff, Daniel Schiff, and Natalia Bueno"
date: "2022"
output: pdf_document
editor_options: 
  chunk_output_type: console
---

#####Setup Chunk#####
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
library(rmarkdown)
library(tidyverse)
library(gridExtra)
library(xtable)
library(stargazer)
library(estimatr)
library(regrrr)
library(dotwhisker)
library(interplot)
library(sandwich)
library(ggpubr)
library(meta)
library(RColorBrewer)
library(rstatix)
options(scipen=999)

#Set here your base directory for saving files
base_dir <- getwd()

```


#####Functions
```{r functions}
dwplot <- function(x,
                   ci = .95,
                   dodge_size = .4,
                   vars_order = NULL,
                   show_intercept = FALSE,
                   margins = FALSE,
                   model_name = "model",
                   model_order = NULL,
                   style = c("dotwhisker", "distribution"),
                   by_2sd = FALSE,
                   vline = NULL,
                   dot_args = list(size = 1.2),
                   whisker_args = list(size = .5),
                   dist_args = list(alpha = .5),
                   line_args = list(alpha = .75, size = 1),
                   ...) {
    # argument checks
    if (length(style) > 1)
        style <- style[[1]]
    if (!style %in% c("dotwhisker", "distribution"))
        stop("style must be dotwhisker or distribution")

    # If x is model object(s), convert to a tidy data frame
    df <- dw_tidy(x, ci, by_2sd, margins, ...)

    if (!show_intercept)
        df <-
        df %>% filter(!grepl("^\\(Intercept\\)$|^\\w+\\|\\w+$", term)) # enable detecting intercept in polr objects

    # Set variables that will appear in pipelines to NULL to make R CMD check happy
    estimate <-
        model <-
        conf.low <-
        conf.high <- term <- std.error <- n <- loc <- dens <- NULL

    n_vars <- length(unique(df$term))
    dodge_size <- dodge_size

    # Confirm number of models, get model names
    if (model_name %in% names(df)) {
        dfmod <- df[[model_name]]
        n_models <- length(unique(dfmod))
        l_models <- if(is.null(model_order)) unique(dfmod) else model_order
        ## re-order/restore levels by order in data set
        df[[model_name]] <- factor(dfmod, levels = rev(l_models))
    } else {
        if (length(df$term) == n_vars) {
            df[[model_name]] <- factor("one")
            n_models <- 1
        } else {
            stop(
                "Please add a variable named '",
                model_name,
                "' to distinguish different models"
            )
        }
    }
    mod_names <- unique(df[[model_name]])

    # Specify order of variables if an order is provided
    if (!is.null(vars_order)) {
        df$term <- factor(df$term, levels = vars_order)
        df <- df[order(df$term),] %>% filter(!is.na(term))
    }

    # Add rows of NAs for variables not included in a particular model
    if (n_models > 1) {
        df <- add_NAs(df, n_models, mod_names)
    }

    # Prep arguments to ggplot
    var_names <- unique(df$term)

    df <- df %>%
        mutate(y_ind = n_vars - as.numeric(factor(term, levels = var_names)) + 1)

    y_ind <- df$y_ind

    # Make the plot
    if (style == "distribution") {
        if (nrow(df) > n_models * n_vars) {
            # reset df if it was passed by relabel_predictors
            df <- df %>%
                select(-n,-loc,-dens) %>%
                distinct()
        }

        df1 <- purrr::map_dfr(1:101, function(x)
            df) %>%
            arrange(term, model) %>%
            group_by(term, model) %>%
            dplyr::mutate(
                n = 1:dplyr::n(),
                loc = estimate - 3 * std.error + (6 * std.error) /
                    100 * (n - 1),
                dens = dnorm(loc, mean = estimate, sd = std.error) + y_ind
            ) %>%
            filter(!is.na(estimate))

        p <- ggplot(data = df) +
            vline +
            geom_dwdist(df1 = df1,
                        line_args = line_args,
                        dist_args = dist_args) +
            scale_y_continuous(breaks = unique(df$y_ind), labels = var_names) +
            guides(color = guide_legend(reverse = TRUE),
                   fill = guide_legend(reverse = TRUE)) +
            ylab("") + xlab("")

    } else {
        # style == "dotwhisker"
        point_args0 <- list(na.rm = TRUE)
        point_args <- c(point_args0, dot_args)
        segment_args0 <- list(na.rm = TRUE)
        segment_args <- c(segment_args0, whisker_args)

        p <- ggplot(data = df) +
            vline +
            geom_dw(
                df = df,
                point_args = point_args,
                segment_args = segment_args,
                dodge_size = dodge_size
            ) +
            guides(color = guide_legend(reverse = TRUE)) +
            ylab("") + xlab("")
    }

    # Omit the legend if there is only one model
    if (n_models == 1) {
        p <- p + theme(legend.position = "none")
    }

    p$args <- list(
        dodge_size = dodge_size,
        vars_order = vars_order,
        show_intercept = show_intercept,
        model_name = model_name,
        model_order = model_order,
        style = style,
        by_2sd = FALSE,
        vline = vline,
        dot_args = dot_args,
        whisker_args = whisker_args,
        dist_args = dist_args,
        line_args = line_args,
        list(...)
    )

    return(p)
}

dw_tidy <- function(x, ci, by_2sd, margins,...) {
    # Set variables that will appear in pipelines to NULL to make R CMD check happy
    estimate <- model <- std.error <- conf.high <- conf.low <- NULL

    AME <- SE <- lower <- p <- upper <- z <- NULL

    ## return model matrix *or* model frame
    get_dat <- function(x) {
        tryCatch(
            as.data.frame(model.matrix(x)),
            error = function(e)
                model.frame(x)
        )
    }
    ## prepend "Model" to numeric-convertable model labels
    mk_model <- function(x) {
        if (all(!is.na(suppressWarnings(as.numeric(x))))) {
            paste("Model", x)
        } else
            x
    }

    if (!is.data.frame(x)) {
        if (!inherits(x, "list")) {
            if(margins){
                df <- margins::margins(x) %>%
                    summary(level = ci) %>%
                    rename(term = factor,
                           estimate = AME,
                           std.error = SE,
                           conf.low = lower,
                           conf.high = upper,
                           statistic = z,
                           p.value = p)
            }else{
                df <- standardize_names(parameters(x, ci, conf.int = TRUE, ...), style = "broom")
            }

            if (by_2sd) {
                df <- df %>% by_2sd(get_dat(x))
            }
        } else {
            # list of models
            if (by_2sd) {
                df <- purrr::map_dfr(x, .id = "model",
                                     ## . has special semantics, can't use
                                     ## it here ...
                                     function(x) {
                                         if(margins){
                                             df <- margins::margins(x) %>%
                                                 summary(level = ci) %>%
                                                 rename(term = factor,
                                                        estimate = AME,
                                                        std.error = SE,
                                                        conf.low = lower,
                                                        conf.high = upper,
                                                        statistic = z,
                                                        p.value = p)
                                         }else{
                                             df <- standardize_names(parameters(x, ci, conf.int = TRUE, ...), style = "broom")
                                         }
                                         dotwhisker::by_2sd(df, dataset = get_dat(x))
                                     }) %>%
                    mutate(model = mk_model(model))
            } else {
                df <- purrr::map_dfr(x, .id = "model",
                                     function(x) {
                                         if(margins){
                                             df <- margins::margins(x) %>%
                                                 summary(level = ci) %>%
                                                 rename(term = factor,
                                                        estimate = AME,
                                                        std.error = SE,
                                                        conf.low = lower,
                                                        conf.high = upper,
                                                        statistic = z,
                                                        p.value = p)
                                         }else{
                                             df <- standardize_names(parameters(x, ci, conf.int = TRUE, ...), style = "broom")
                                         }
                                     }) %>%
                    mutate(model = if_else(
                        !is.na(suppressWarnings(as.numeric(
                            model
                        ))),
                        paste("Model", model),
                        model
                    ))
            }
        }
    } else {
        # x is a dataframe
        df <- x
        if ((!"conf.low" %in% names(df)) ||
            (!"conf.high" %in% names(df))) {
            if ("std.error" %in% names(df)) {
                df <- transform(
                    df,
                    conf.low = estimate - stats::qnorm(1 - (1 - ci) /
                                                           2) * std.error,
                    conf.high = estimate + stats::qnorm(1 - (1 - ci) /
                                                            2) * std.error
                )
            } else {
                df <- transform(df,
                                conf.low = NA,
                                conf.high = NA)
            }
        }
    }
    return(df)
}

add_NAs <-
    function(df = df,
             n_models = n_models,
             mod_names = mod_names,
             model_name = "model") {
        # Set variables that will appear in pipelines to NULL to make R CMD check happy
        term <- model <- NULL

        if (!is.factor(df$term)) {
            df$term <- factor(df$term, levels = unique(df$term))
        }
        if (!is.factor(dfmod <- df[[model_name]])) {
            df[[model_name]] <- factor(dfmod, levels = unique(dfmod))
        }
        for (i in seq(n_models)) {
            m <-
                df %>% filter(model == factor(mod_names[[i]], levels = mod_names))
            not_in <- setdiff(unique(df$term), m$term)
            for (j in seq(not_in)) {
                t <- data.frame(
                    term = factor(not_in[j], levels = levels(df$term)),
                    model = factor(mod_names[[i]], levels = mod_names)
                )
                if ("submodel" %in% names(m)) {
                    t$submodel <- m$submodel[1]
                }
                if ("submodel" %in% names(m)) {
                    m <- full_join(m, t, by = c("term", "model", "submodel"))
                } else {
                    m <- full_join(m, t, by = c("term", "model"))
                }
            }
            if (i == 1) {
                dft <- m %>% arrange(term)
            } else {
                dft <- bind_rows(dft, m %>% arrange(term))
            }
        }

        df <- dft

        df$estimate <- as.numeric(df$estimate)
        if ("std.error" %in% names(df)) {
            df$std.error <- as.numeric(df$std.error)
        }
        if ("conf.high" %in% names(df)) {
            df$conf.high <- as.numeric(df$conf.high)
        }
        if ("conf.low" %in% names(df)) {
            df$conf.low <- as.numeric(df$conf.low)
        }

        return(df)
    }

geom_dwdist <- function(data = NULL, df1, line_args, dist_args) {
    # Set variables to NULL to make R CMD check happy
    loc <-
        dens <- model <- term <- y_ind <- conf.high <- conf.low <- NULL

    l1 <- layer(
        data = df1,
        mapping = aes(
            x = loc,
            y = dens,
            group = interaction(model, term),
            color = model,
            fill = model
        ),
        stat = "identity",
        position = "identity",
        geom = GeomPolygon,
        params = dist_args
    )
    l2 <- layer(
        data = data,
        mapping = aes(
            y = y_ind,
            xmin = conf.low,
            xmax = conf.high,
            color = model
        ),
        stat = "identity",
        position = "identity",
        geom = ggstance::GeomLinerangeh,
        show.legend = TRUE,
        params = line_args
    )
    return(list(l1, l2))
}

geom_dw <- function(df, point_args, segment_args, dodge_size) {
    # Set variables to NULL to make R CMD check happy
    loc <-
        dens <-
        model <- term <- y_ind <- conf.high <- conf.low <- estimate <- NULL

    point_arguments <-
        tryCatch({
            added_point_aes <- point_args[names(point_args) == ""][[1]]
            point_mapping <-
                modifyList(
                    aes(
                        y = stats::reorder(term, y_ind),
                        x = estimate,
                        group = interaction(model, term),
                        color = model
                    ),
                    added_point_aes
                )
            point_arguments <- point_args[names(point_args) != ""]
            list(point_mapping, point_arguments)
        },
        error = function(e) {
            point_mapping <-
                aes(
                    y = stats::reorder(term, y_ind),
                    x = estimate,
                    group = interaction(model, term),
                    color = model
                )
            return(list(point_mapping, point_args))
        })

    segment_arguments <-
        tryCatch({
            added_segment_aes <- segment_args[names(segment_args) == ""][[1]]
            segment_mapping <-
                modifyList(
                    aes(
                        y = stats::reorder(term, y_ind),
                        xmin = conf.low,
                        xmax = conf.high,
                        group = interaction(model, term),
                        color = model
                    ),
                    added_segment_aes
                )
            segment_arguments <- segment_args[names(segment_args) != ""]
            list(segment_mapping, segment_arguments)
        },
        error = function(e) {
            segment_mapping <-
                aes(
                    y = stats::reorder(term, y_ind),
                    xmin = conf.low,
                    xmax = conf.high,
                    group = interaction(model, term),
                    color = model
                )
            return(list(segment_mapping, segment_args))
        })


    l1 <- layer(
        data = df,
        mapping = point_arguments[[1]],
        stat = "identity",
        position = ggstance::position_dodgev(height = dodge_size),
        geom = "point",
        params = point_arguments[[2]]
    )
    l2 <- layer(
        data = df,
        mapping = segment_arguments[[1]],
        stat = "identity",
        position = ggstance::position_dodgev(height = dodge_size),
        geom = ggstance::GeomLinerangeh,
        show.legend = TRUE,
        params = segment_arguments[[2]]
    )
    return(list(l2, l1))
}
```


#####Read in the Clean Data
```{r read in data}
ld1 <- readRDS("data/df_clean.rds")
ld2 <- readRDS("data/df_followup_clean.rds")
ld3 <- readRDS("data/df_followup2_clean.rds")
ld4 <- readRDS("data/df_study4_clean.rds")
ld5 <- readRDS("data/df_study5_clean.rds")

ld1$treatment <- if_else(ld1$alleg_treatment == "Info. Uncertain" | ld1$alleg_treatment == "Opp. Rally", 1, 0)
ld4$treatment <- if_else(ld4$alleg_treatment == "Info. Uncertain" | ld4$alleg_treatment == "Opp. Rally", 1, 0)
ld5$treatment <- if_else(ld5$alleg_treatment == "Info. Uncertain" | ld5$alleg_treatment == "Opp. Rally", 1, 0)

#Overall sample size
nrow(ld1) + nrow(ld2) + nrow(ld3) + nrow(ld4) + nrow(ld5)

#Sample size for text
nrow(ld1 %>% filter(ld1$media_format=="Text")) + nrow(ld2) + nrow(ld3) + nrow(ld4 %>% filter(ld4$media_format=="Text")) + nrow(ld5)

#Sample size for video
nrow(ld1 %>% filter(ld1$media_format=="Video")) + nrow(ld4 %>% filter(ld4$media_format=="Video"))
```


#####Table 1: Summary Information about Survey Experiments
```{r table 1}
study <- c("Study 1", "Study 2", "Study 3", "Study 4", "Study 5")
date <- c("Feb 2021", "May 2021", "Oct 2021", "Nov 2022", "Nov 2022")
platform <- c("Lucid", "Lucid", "Lucid", "Prolific", "Lucid")
sample_size <- c(nrow(ld1), nrow(ld2), nrow(ld3), nrow(ld4), nrow(ld5))
treatments <- c("Nonresponse, IU, OR",
                "Nonresponse, IU; Nonresponse, OR",
                "IU, Apology, Simple Denial",
                "Nonresponse, IU, OR",
                "Nonresponse, IU, OR")
media_format <- c("Text or Video", "Text only", "Text only", "Text or Video", "Text only")
summary_surveys <- cbind(study, date, platform, sample_size, media_format, treatments) %>% as.data.frame()
colnames(summary_surveys) <- c("Study", "Date", "Platform", "\\textit{n}", "Scandal Format", "Politician Response Treatments")
print(xtable(summary_surveys, caption="Summary Information about Survey Experiments", label="tab:summary_surveys"), include.rownames=F, file=file.path(base_dir, "Tables/summary_surveys.tex"), caption.placement="top", size="\\small", sanitize.text.function = identity)

```


#####Figure 1: Treatment Wordings for Claims of Misinformation
No code required, includes the exact wordings of the informational uncertainty and oppositional rallying treatments


#####Figure 2: Experimental Design for Studies 1 and 4
No code required, visual representation of Study 1 randomization, treatments, and outcomes


#####Figure 3: Liar's Dividend Results for Study 1 and Study 4
#####Table B6: Figure 3 Regression Results - Study 1
#####Table B7: Figure 3 Regression Results - Study 1, Attentive
#####Table B8: Figure 3 Regression Results - Study 4
#####Table B9: Figure 3 Regression Results - Study 4, Attentive
```{r}
#Figure 3a
mechs_support_text <- lm_robust(data = ld1 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_text

mechs_support_video <- lm_robust(data = ld1 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_video

mechs_support_text_att <- lm_robust(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

mechs_support_video_att <- lm_robust(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_1_support <- rbind(mechs_support_text[2,], mechs_support_video[2,], mechs_support_text[3,], mechs_support_video[3,], 
                         mechs_support_text_att[2,], mechs_support_video_att[2,], mechs_support_text_att[3,], mechs_support_video_att[3,])
study_1_support
study_1_support$model <- c(rep(c("Text", "Video"), 2),
                           rep(c("Text, Attentive", "Video, Attentive"), 2))
study_1_support$media <- rep(rep(c("Text", "Video"), 2), 2)
study_1_support$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), each = 2), 2)
study_1_support$attentive <- rep(c("Full", "Attentive Only"), each = 4)


study_1_support_plot <- dwplot(study_1_support %>% arrange(model),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = media, color = media), size = 2.5),
whisker_args = list(aes(linetype = attentive, color = media)))  +
scale_color_manual(name = "Media Format", 
                   labels = c("Text", "Video") %>% rev(),
                   breaks=c("Text", "Video") %>% rev(),
                   values = c("#F8766D", "#619CFF")) +
 scale_shape_manual(name = "Media Format", 
                    labels = c("Text", "Video"), 
                    breaks=c("Text", "Video"),
                    values = c(15, 17)) +
  scale_linetype_manual(name = "Sample", 
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"), 
                        values = c(1,2)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
study_1_support_plot

pdf(file.path(base_dir, "Figures/study_1_support.pdf"), width=7.5, height=4.5)
study_1_support_plot
dev.off()

#Figure 3b
mechs_support_text <- lm_robust(data = ld4 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_text

mechs_support_video <- lm_robust(data = ld4 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_video

mechs_support_text_att <- lm_robust(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

mechs_support_video_att <- lm_robust(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_support <- rbind(mechs_support_text[2,], mechs_support_video[2,], mechs_support_text[3,], mechs_support_video[3,],
                         mechs_support_text_att[2,], mechs_support_video_att[2,], mechs_support_text_att[3,], mechs_support_video_att[3,])
study_4_support
study_4_support$model <- c(rep(c("Text", "Video"), 2),
                           rep(c("Text, Attentive", "Video, Attentive"), 2))
study_4_support$media <- rep(rep(c("Text", "Video"), 2), 2)
study_4_support$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), each = 2), 2)
study_4_support$attentive <- rep(c("Full", "Attentive Only"), each = 4)


study_4_support_plot <- dwplot(study_4_support %>% arrange(model),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = media, color = media), size = 2.5),
whisker_args = list(aes(linetype = attentive, color = media)))  +
scale_color_manual(name = "Media Format", 
                   labels = c("Text", "Video") %>% rev(),
                   breaks=c("Text", "Video") %>% rev(),
                   values = c("#F8766D", "#619CFF")) +
 scale_shape_manual(name = "Media Format", 
                    labels = c("Text", "Video"), 
                    breaks=c("Text", "Video"),
                    values = c(15, 17)) +
  scale_linetype_manual(name = "Sample", 
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"), 
                        values = c(1,2)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Replication: Effects on Politician Support Index") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
study_4_support_plot

pdf(file.path(base_dir, "Figures/study_4_support.pdf"), width=7.5, height=4.5)
study_4_support_plot
dev.off()


#Table B6
m4 <- lm(data = ld1 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m6 <- lm(data = ld1 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m4, m6,
          se = starprep(m4, m6),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", 
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican", 
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 3 Regression Results - Study 1",
          label="tab:fig_2",
          star.char = c("+","*","**","***"), 
          star.cutoffs = c(0.1,0.05,0.01,0.001), 
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          add.lines = list(c("Sample", "Study 1 Text", "Study 1 Video")),
          style="APSR",
          header=F,
          type="latex",
          font.size="scriptsize",
          out=file.path(base_dir, "Tables/fig_2_table.tex"))

#Table B7
m4 <- lm(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m6 <- lm(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m4, m6,
          se = starprep(m4, m6),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", 
                             "Strong Democrat", "Democrat", "Lean Democrat", "Lean Republican", "Republican", 
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 3 Regression Results - Study 1, Attentive",
          label="tab:fig_2_attentive",
          font.size="tiny",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
          add.lines = list(c("Sample", "Study 1 Att. Text", "Study 1 Att. Video")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_2_table_attentive.tex"))

#Table B8
m4 <- lm(data = ld4 %>% filter(media_format == "Text"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m6 <- lm(data = ld4 %>% filter(media_format == "Video"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m4, m6,
          se = starprep(m4, m6),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat",
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 3 Regression Results - Study 4",
          label="tab:fig_2_replication",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          add.lines = list(c("Sample", "Study 4 Text", "Study 4 Video")),
          style="APSR",
          header=F,
          type="latex",
          font.size="scriptsize",
          out=file.path(base_dir, "Tables/fig_2_table_replication.tex"))

#Table B9
m4 <- lm(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m6 <- lm(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Video"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m4, m6,
          se = starprep(m4, m6),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat",
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 3 Regression Results - Study 4, Attentive",
          label="tab:fig_2_replication_attentive",
          star.char = c("+","*","**","***"),
          star.cutoffs = c(0.1,0.05,0.01,0.001),
          notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          add.lines = list(c("Sample", "Study 4 Att. Text", "Study 4 Att. Video")),
          style="APSR",
          header=F,
          type="latex",
          font.size="tiny",
          out=file.path(base_dir, "Tables/fig_2_table_replication_attentive.tex"))

#Pooled Allegation Estimates

ld_support_1 <- lm_robust(data = ld1, 
                        support ~ treatment +
                          party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_1 #0.07
ld_support_4 <- lm_robust(data = ld4, 
                        support ~ treatment +
                          party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_4 #0.16

#Pooled allegations Study 1 and Study 4
ates <- c(ld_support_1[2,2], ld_support_4[2,2]) %>% unlist %>% unname
ses <- c(ld_support_1[2,3], ld_support_1[2,3]) %>% unlist %>% unname
support <- cbind(ates, ses) %>% as_tibble()
support_meta <- metagen(data = support, TE = ates, seTE = ses)
pooled_support <- c("Pooled Alleg.", support_meta$TE.fixed, support_meta$seTE.fixed, support_meta$statistic.fixed, support_meta$pval.fixed, support_meta$TE.fixed - 1.96*support_meta$seTE.fixed,
                       support_meta$TE.fixed + 1.96*support_meta$seTE.fixed)

#Pooled Study 1 and 4 Allegation, Text Only

ld_support_1_text <- lm_robust(data = ld1 %>% filter(media_format == "Text"), 
                          support ~ treatment +
                            party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_1_text #0.15

ld_support_4_text <- lm_robust(data = ld4 %>% filter(media_format == "Text"), 
                          support ~ treatment +
                            party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_4_text #0.22

ates <- c(ld_support_1_text[2,2], ld_support_4_text[2,2]) %>% unlist %>% unname
ses <- c(ld_support_1_text[2,3], ld_support_1_text[2,3]) %>% unlist %>% unname
support_text <- cbind(ates, ses) %>% as_tibble()
support_text_meta <- metagen(data = support_text, TE = ates, seTE = ses)
pooled_text_support <- c("Pooled Alleg. Text", support_text_meta$TE.fixed, support_text_meta$seTE.fixed, 
                         support_text_meta$statistic.fixed, support_text_meta$pval.fixed, 
                         support_text_meta$TE.fixed - 1.96*support_text_meta$seTE.fixed,
                    support_text_meta$TE.fixed + 1.96*support_text_meta$seTE.fixed)


#Pooled Study 1 and 4 Allegation, Video Only

ld_support_1_video <- lm_robust(data = ld1 %>% filter(media_format == "Video"), 
                               support ~ treatment +
                                 party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_1_video #-0.009767236

ld_support_4_video <- lm_robust(data = ld4 %>% filter(media_format == "Video"), 
                               support ~ treatment +
                                 party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
ld_support_4_video #0.09700840

ates <- c(ld_support_1_video[2,2], ld_support_4_video[2,2]) %>% unlist %>% unname
ses <- c(ld_support_1_video[2,3], ld_support_1_video[2,3]) %>% unlist %>% unname
support_video <- cbind(ates, ses) %>% as_tibble()
support_video_meta <- metagen(data = support_video, TE = ates, seTE = ses)
pooled_video_support <- c("Pooled Alleg. Text", support_video_meta$TE.fixed, support_video_meta$seTE.fixed, 
                         support_video_meta$statistic.fixed, support_video_meta$pval.fixed, 
                         support_video_meta$TE.fixed - 1.96*support_video_meta$seTE.fixed,
                         support_video_meta$TE.fixed + 1.96*support_video_meta$seTE.fixed)


#Impact on just the first support measure
mechs_support_text_1 <- lm_robust(data = ld1 %>% filter(media_format == "Text"), 
                                support_1 ~ alleg_treatment +
                                  party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_text_1[2,2] #0.26, unstandardized impact of text IU on support 1 measure

mechs_support_text_2 <- lm_robust(data = ld4 %>% filter(media_format == "Text"), 
                                support_1 ~ alleg_treatment +
                                  party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
mechs_support_text_2[2,2] #0.29, unstandardized impact of text IU on support 1 measure


#Reduction in percentage of opponents
ld1$support_binary <- if_else(ld1$support_1<=2, 0, 1)
ld1 %>% filter(media_format=="Text") %>% group_by(alleg_treatment) %>% summarize(prop_opponents = length(which(support_binary==0))/length(support_binary)) #decrease from 44% opponents to 32-34% opponents

ld4$support_binary <- if_else(ld4$support_1<=2, 0, 1)
ld4 %>% filter(media_format=="Text") %>% group_by(alleg_treatment) %>% summarize(prop_opponents = length(which(support_binary==0))/length(support_binary)) #decrease from 44% opponents to 32-34% opponents

#IU pooled across study 1 and study 4
study_1_IU <- lm_robust(data = ld1, 
                          support ~ alleg_treatment +
                            party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_IU <- lm_robust(data = ld4, 
                          support ~ alleg_treatment +
                            party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_IU[2,2], study_4_IU[2,2]) %>% unlist %>% unname
ses <- c(study_1_IU[2,3], study_4_IU[2,3]) %>% unlist %>% unname
support_IU <- cbind(ates, ses) %>% as_tibble()
support_IU_meta <- metagen(data = support_IU, TE = ates, seTE = ses)
pooled_support_IU <- c("Pooled IU", support_IU_meta$TE.fixed, support_IU_meta$seTE.fixed, support_IU_meta$statistic.fixed, support_IU_meta$pval.fixed, support_IU_meta$TE.fixed - 1.96*support_IU_meta$seTE.fixed,
                       support_IU_meta$TE.fixed + 1.96*support_IU_meta$seTE.fixed)

#OR pooled across study 1 and study 4

study_1_OR <- lm_robust(data = ld1, 
                        support ~ alleg_treatment +
                          party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_OR <- lm_robust(data = ld4, 
                        support ~ alleg_treatment +
                          party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_OR[3,2], study_4_OR[3,2]) %>% unlist %>% unname
ses <- c(study_1_OR[3,3], study_4_OR[3,3]) %>% unlist %>% unname
support_OR <- cbind(ates, ses) %>% as_tibble()
support_OR_meta <- metagen(data = support_OR, TE = ates, seTE = ses)
pooled_support_IU <- c("Pooled IU", support_OR_meta$TE.fixed, support_OR_meta$seTE.fixed, support_OR_meta$statistic.fixed, 
                       support_OR_meta$pval.fixed, support_OR_meta$TE.fixed - 1.96*support_OR_meta$seTE.fixed,
                       support_OR_meta$TE.fixed + 1.96*support_OR_meta$seTE.fixed)

#Comparing estimates of OR between Study 1 and Study 4
z_score <- (study_1_OR[3,2] - study_4_OR[3,2])/(sqrt(study_1_OR[3,3]^2 + study_4_OR[3,3]^2)) 
2*(1 - pnorm(abs(z_score))) #0.04


#Are the differences between text and video significant?
ld1$video <- if_else(ld1$media_format=="Video", 1, 0)
vid_text <- lm_robust(data = ld1, 
                   support ~ alleg_treatment*video +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
#IU video versus text
vid_text$p.value[vid_text$term=="alleg_treatmentInfo. Uncertain:video"] #0.048
#OR video versus text
vid_text$p.value[vid_text$term=="alleg_treatmentOpp. Rally:video"] #0.041


#Did the IU treatment increase variance in belief?
var(ld1$belief[ld1$alleg_treatment=="Info. Uncertain"]) #0.83
var(ld1$belief[ld1$alleg_treatment=="Control"]) #1


#Replication: Are the differences between text and video significant?
ld4$video <- if_else(ld4$media_format=="Video", 1, 0)
vid_text <- lm_robust(data = ld4,
                   support ~ alleg_treatment*video +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
#IU video versus text
vid_text$p.value[vid_text$term=="alleg_treatmentInfo. Uncertain:video"] #0.01
#OR video versus text
vid_text$p.value[vid_text$term=="alleg_treatmentOpp. Rally:video"] #0.32


#Are Study 1 and Study 4 OR video results significantly different?
vid_1 <- lm_robust(data = ld1 %>% filter(media_format == "Video"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
vid_4 <- lm_robust(data = ld4 %>% filter(media_format == "Video"),
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
z_score <- (vid_1[3,2] - vid_4[3,2])/(sqrt(vid_1[3,3]^2 + vid_4[3,3]^2)) 
2*(1 - pnorm(abs(z_score))) #0.04

#Increased deepfake familiarity?
mean(ld1$digital_literacy, na.rm=T) #2.8
mean(ld4$digital_literacy, na.rm=T) #3.1
t.test(ld1$digital_literacy, ld4$digital_literacy) #significantly different
table(ld1$digital_literacy) %>% prop.table() #22% had not heard about deepfakes
table(ld4$digital_literacy) %>% prop.table() #8% had not heard about deepfakes

#Increase partisanship?
length(which(ld1$party=="Independent"))/nrow(ld1)*100 #27%
length(which(ld4$party=="Independent"))/nrow(ld4)*100 #23%
ld1$independent <- if_else(ld1$party=="Independent", 1, 0)
ld4$independent <- if_else(ld4$party=="Independent", 1, 0)
t.test(ld1$independent, ld4$independent) #significantly different

```


#####Figure 4: Liar's Dividend Results for Studies 1, 2, 4, and 5
#####Table B10: Figure 4 Regression Results - Text
#####Table B11: Figure 4 Regression Results - Text, Attentive
#####Table B12: Figure 4 Regression Results - Video
#####Table B13: Figure 4 Regression Results - Video, Attentive
```{r}
#Figure 4a
study_1_text <- lm_robust(data = ld1 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_2_IU <- lm_robust(data = ld2, 
                   support_exp1 ~ alleg_treatment_1 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_text <- lm_robust(data = ld4 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_5_text <- lm_robust(data = ld5, 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_text[2,2], study_2_IU[2,2], study_4_text[2,2], study_5_text[2,2]) %>% unlist %>% unname
ses <- c(study_1_text[2,3], study_2_IU[2,3], study_4_text[2,3], study_5_text[2,3]) %>% unlist %>% unname
support_IU <- cbind(ates, ses) %>% as_tibble()
support_IU_meta <- metagen(data = support_IU, TE = ates, seTE = ses)
pooled_support_IU <- c("Pooled IU", support_IU_meta$TE.fixed, support_IU_meta$seTE.fixed, support_IU_meta$statistic.fixed, support_IU_meta$pval.fixed, support_IU_meta$TE.fixed - 1.96*support_IU_meta$seTE.fixed,
                       support_IU_meta$TE.fixed + 1.96*support_IU_meta$seTE.fixed)


study_2_OR <- lm_robust(data = ld2, 
                   support_exp2 ~ alleg_treatment_2 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_text[3,2], study_2_OR[2,2], study_4_text[3,2], study_5_text[3,2]) %>% unlist %>% unname
ses <- c(study_1_text[3,3], study_2_OR[2,3], study_4_text[3,3], study_5_text[3,3]) %>% unlist %>% unname
support_OR <- cbind(ates, ses) %>% as_tibble()
support_OR_meta <- metagen(data = support_OR, TE = ates, seTE = ses)
pooled_support_OR <- c("Pooled OR", support_OR_meta$TE.fixed, support_OR_meta$seTE.fixed, support_OR_meta$statistic.fixed, support_OR_meta$pval.fixed, support_OR_meta$TE.fixed - 1.96*support_OR_meta$seTE.fixed,
                       support_OR_meta$TE.fixed + 1.96*support_OR_meta$seTE.fixed)

study_1_text_att <- lm_robust(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_2_IU_att <- lm_robust(data = ld2 %>% filter(attentiveness==2), 
                   support_exp1 ~ alleg_treatment_1 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_text_att <- lm_robust(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_5_text_att <- lm_robust(data = ld5 %>% filter(attentiveness==2), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_text_att[2,2], study_2_IU_att[2,2], study_4_text_att[2,2], study_5_text_att[2,2]) %>% unlist %>% unname
ses <- c(study_1_text_att[2,3], study_2_IU_att[2,3], study_4_text_att[2,3], study_5_text_att[2,3]) %>% unlist %>% unname
support_IU_att <- cbind(ates, ses) %>% as_tibble()
support_IU_meta_att <- metagen(data = support_IU_att, TE = ates, seTE = ses)
pooled_support_IU_att <- c("Pooled IU", support_IU_meta_att$TE.fixed, support_IU_meta_att$seTE.fixed, support_IU_meta_att$statistic.fixed, support_IU_meta_att$pval.fixed, support_IU_meta_att$TE.fixed - 1.96*support_IU_meta_att$seTE.fixed,
                       support_IU_meta_att$TE.fixed + 1.96*support_IU_meta_att$seTE.fixed)


study_2_OR_att <- lm_robust(data = ld2 %>% filter(attentiveness==2), 
                   support_exp2 ~ alleg_treatment_2 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_text_att[3,2], study_2_OR_att[2,2], study_4_text_att[3,2], study_5_text_att[3,2]) %>% unlist %>% unname
ses <- c(study_1_text_att[3,3], study_2_OR_att[2,3], study_4_text_att[3,3], study_5_text_att[3,3]) %>% unlist %>% unname
support_OR_att <- cbind(ates, ses) %>% as_tibble()
support_OR_meta_att <- metagen(data = support_OR_att, TE = ates, seTE = ses)
pooled_support_OR_att <- c("Pooled OR", support_OR_meta_att$TE.fixed, support_OR_meta_att$seTE.fixed, support_OR_meta_att$statistic.fixed, support_OR_meta_att$pval.fixed, support_OR_meta_att$TE.fixed - 1.96*support_OR_meta_att$seTE.fixed,
                       support_OR_meta_att$TE.fixed + 1.96*support_OR_meta_att$seTE.fixed)


study_2_support <- rbind(study_1_text[2,1:5], study_2_IU[2,1:5], study_4_text[2,1:5], study_5_text[2,1:5], pooled_support_IU, 
                         study_1_text[3,1:5], study_2_OR[2,1:5], study_4_text[3,1:5], study_5_text[3,1:5], pooled_support_OR,
                         study_1_text_att[2,1:5], study_2_IU_att[2,1:5], study_4_text_att[2,1:5], study_5_text_att[2,1:5], pooled_support_IU_att, 
                         study_1_text_att[3,1:5], study_2_OR_att[2,1:5], study_4_text_att[3,1:5], study_5_text_att[3,1:5], pooled_support_OR_att)
study_2_support[,-1] <- sapply(study_2_support[,-1], as.numeric)
study_2_support
study_2_support$model <- c(rep(c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled"), 2),
                           rep(c("Study 1 Attentive", "Study 2 Attentive", "Study 4 Attentive", "Study 5 Attentive", "Pooled Attentive"), 2))
study_2_support$study <- factor(rep(c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled"), 2), levels = c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled"))
study_2_support$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), each = 5), 2)
study_2_support$attentive <- rep(c("Full", "Attentive Only"), each = 10)

#Pooled, Text Estimates for IU and OR
study_2_support[5,]
study_2_support[10,]

study_2_support_plot <- dwplot(study_2_support %>% arrange(study),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = study, color = study), size = 2.5),
whisker_args = list(aes(linetype = attentive, color = study)),
dodge_size = 0.8)  +
scale_color_manual(name = "Study", 
                   labels = c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled") %>% rev(),
                   breaks=c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled") %>% rev(), 
                   values = c("#7570B3", "#E6AB02", "#E7298A", "#D95F02", "#1B9E77")) + 
 scale_shape_manual(name = "Study", 
                      labels=c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled"),
                      breaks=c("Study 1", "Study 2", "Study 4", "Study 5", "Pooled"),
                    values = c(15, 17, 16, 18, 4)) +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"), 
                        values = c(1,2)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index for Text") +
    xlim(-.25, .6) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
study_2_support_plot

pdf(file.path(base_dir, "Figures/all_studies_support.pdf"), width=7.5, height=4.5)
study_2_support_plot
dev.off()

#Table B10
m1 <- lm(data = ld1 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m2 <- lm(data = ld2, 
                   support_exp1 ~ alleg_treatment_1 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m3 <- lm(data = ld2, 
                   support_exp2 ~ alleg_treatment_2 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m4 <- lm(data = ld4 %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m5 <- lm(data = ld5, 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m1, m2, m3, m4, m5,
          se = starprep(m1, m2, m3, m4, m5),
          omit = c("Fact Check"),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Info. Uncertain", 
                             "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Politician Support Index"),
          column.separate = c(5),
          keep.stat = c("n","rsq"),
          title="Figure 4 Regression Results - Text",
          label="tab:fig_3",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Study 1 Text", "Study 2", "Study 2", "Study 4 Text", "Study 5")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_3_table_all_studies.tex"))

#Table B11
m1 <- lm(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m2 <- lm(data = ld2 %>% filter(attentiveness==2), 
                   support_exp1 ~ alleg_treatment_1 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m3 <- lm(data = ld2 %>% filter(attentiveness==2), 
                   support_exp2 ~ alleg_treatment_2 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m4 <- lm(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)
m5 <- lm(data = ld5 %>% filter(attentiveness==2), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m1, m2, m3, m4, m5,
          se = starprep(m1, m2, m3, m4, m5),
          omit = c("Fact Check"),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Info. Uncertain", 
                             "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Politician Support Index"),
          column.separate = c(5),
          keep.stat = c("n","rsq"),
          title="Figure 4 Regression Results - Text, Attentive",
          label="tab:fig_3_attentive",
          font.size="tiny",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Study 1 Att. Text", "Study 2 Att.", "Study 2 Att.", "Study 4 Att. Text", "Study 5 Att.")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_3_table_all_studies_attentive.tex"))


#Figure 4b
study_1_video <- lm_robust(data = ld1 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_video <- lm_robust(data = ld4 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_video[2,2], study_4_video[2,2]) %>% unlist %>% unname
ses <- c(study_1_video[2,3], study_4_video[2,3]) %>% unlist %>% unname
support_IU <- cbind(ates, ses) %>% as_tibble()
support_IU_meta <- metagen(data = support_IU, TE = ates, seTE = ses)
pooled_support_IU <- c("Pooled IU", support_IU_meta$TE.fixed, support_IU_meta$seTE.fixed, support_IU_meta$statistic.fixed, support_IU_meta$pval.fixed, support_IU_meta$TE.fixed - 1.96*support_IU_meta$seTE.fixed,
                       support_IU_meta$TE.fixed + 1.96*support_IU_meta$seTE.fixed)

ates <- c(study_1_video[3,2], study_4_video[3,2]) %>% unlist %>% unname
ses <- c(study_1_video[3,3], study_4_video[3,3]) %>% unlist %>% unname
support_OR <- cbind(ates, ses) %>% as_tibble()
support_OR_meta <- metagen(data = support_OR, TE = ates, seTE = ses)
pooled_support_OR <- c("Pooled OR", support_OR_meta$TE.fixed, support_OR_meta$seTE.fixed, support_OR_meta$statistic.fixed, support_OR_meta$pval.fixed, support_OR_meta$TE.fixed - 1.96*support_OR_meta$seTE.fixed,
                       support_OR_meta$TE.fixed + 1.96*support_OR_meta$seTE.fixed)

study_1_video_att <- lm_robust(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

study_4_video_att <- lm_robust(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy

ates <- c(study_1_video_att[2,2], study_4_video_att[2,2]) %>% unlist %>% unname
ses <- c(study_1_video_att[2,3], study_4_video_att[2,3]) %>% unlist %>% unname
support_IU_att <- cbind(ates, ses) %>% as_tibble()
support_IU_meta_att <- metagen(data = support_IU_att, TE = ates, seTE = ses)
pooled_support_IU_att <- c("Pooled IU", support_IU_meta_att$TE.fixed, support_IU_meta_att$seTE.fixed, support_IU_meta_att$statistic.fixed, support_IU_meta_att$pval.fixed, support_IU_meta_att$TE.fixed - 1.96*support_IU_meta_att$seTE.fixed,
                       support_IU_meta_att$TE.fixed + 1.96*support_IU_meta_att$seTE.fixed)

ates <- c(study_1_video_att[3,2], study_4_video_att[3,2]) %>% unlist %>% unname
ses <- c(study_1_video_att[3,3], study_4_video_att[3,3]) %>% unlist %>% unname
support_OR_att <- cbind(ates, ses) %>% as_tibble()
support_OR_meta_att <- metagen(data = support_OR_att, TE = ates, seTE = ses)
pooled_support_OR_att <- c("Pooled OR", support_OR_meta_att$TE.fixed, support_OR_meta_att$seTE.fixed, support_OR_meta_att$statistic.fixed, support_OR_meta_att$pval.fixed, support_OR_meta_att$TE.fixed - 1.96*support_OR_meta_att$seTE.fixed,
                       support_OR_meta_att$TE.fixed + 1.96*support_OR_meta_att$seTE.fixed)


study_2_support <- rbind(study_1_video[2,1:5], study_4_video[2,1:5], pooled_support_IU, 
                         study_1_video[3,1:5], study_4_video[3,1:5], pooled_support_OR,
                         study_1_video_att[2,1:5], study_4_video_att[2,1:5], pooled_support_IU_att, 
                         study_1_video_att[3,1:5], study_4_video_att[3,1:5], pooled_support_OR_att)
study_2_support[,-1] <- sapply(study_2_support[,-1], as.numeric)
study_2_support
study_2_support$model <- c(rep(c("Study 1", "Study 4", "Pooled"), 2),
                           rep(c("Study 1 Attentive", "Study 4 Attentive", "Pooled Attentive"), 2))
study_2_support$study <- factor(rep(c("Study 1", "Study 4", "Pooled"), 2), levels = c("Study 1", "Study 4", "Pooled"))
study_2_support$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), each = 3), 2)
study_2_support$attentive <- rep(c("Full", "Attentive Only"), each = 6)


study_2_support_plot <- dwplot(study_2_support %>% arrange(study),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(aes(shape = study, color = study), size = 2.5),
whisker_args = list(aes(linetype = attentive, color = study)),
dodge_size = 0.48)  +
scale_color_manual(name = "Study", 
                   labels = c("Study 1", "Study 4", "Pooled") %>% rev(),
                   breaks=c("Study 1", "Study 4", "Pooled") %>% rev(), 
                   values = c("#7570B3", "#E7298A", "#1B9E77")) + 
 scale_shape_manual(name = "Study", 
                      labels=c("Study 1", "Study 4", "Pooled"),
                      breaks=c("Study 1", "Study 4", "Pooled"),
                    values = c(15, 16, 4)) +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"), 
                        values = c(1,2)) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index for Video") +
    xlim(-.25, .6) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
study_2_support_plot

pdf(file.path(base_dir, "Figures/all_studies_support_video.pdf"), width=7.5, height=4.5)
study_2_support_plot
dev.off()


#Table B12
m1 <- lm(data = ld1 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m4 <- lm(data = ld4 %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m1, m4,
          se = starprep(m1, m4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Politician Support Index"),
          column.separate = c(2),
          keep.stat = c("n","rsq"),
          title="Figure 4 Regression Results - Video",
          label="tab:fig_3_video",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Study 1 Video", "Study 4 Video")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_3_table_video.tex"))

#Table B13
m1 <- lm(data = ld1 %>% filter(attentiveness==2) %>%  filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

m4 <- lm(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Video"), 
                   support ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(m1, m4,
          se = starprep(m1, m4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Politician Support Index"),
          column.separate = c(2),
          keep.stat = c("n","rsq"),
          title="Figure 4 Regression Results - Video, Attentive",
          label="tab:fig_3_video_attentive",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Study 1 Att. Video", "Study 4 Att. Video")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_3_table_video_attentive.tex"))


#Significance of IU effect in Study 2
m2 <- lm_robust(data = ld2, support_exp1 ~ alleg_treatment_1 + party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
m2$p.value[m2$term=="alleg_treatment_1Info. Uncertain"] #0.086


#Exploring correlations
#Subset to people who received the IU treatment
df_IU <- ld2 %>% filter(alleg_treatment_1 == "Info. Uncertain")
#Correlation between believing the politician allegation and support
cor(df_IU$belief_alleg, df_IU$support_exp1) #0.38
#Correlation between agreement with statement that ``it's hard to know what's true these days'' and support
cor(df_IU$uncertainty, df_IU$support_exp1) #0.22
#Correlation between believing the politician allegation and belief in scandal
cor(df_IU$belief_alleg, df_IU$belief_1) #-0.003

```


#####Figure 5: Heterogeneous Effects of Oppositional Rallying and Informational Uncertainty
#####Table B14: Figure 5 Regression Results
#####Table B15: Figure 5 Regression Results - Attentive
```{r}
#IU pooled
ld3_IU <- ld1 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% filter(alleg_treatment_1 != "Fact Check") %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp1, belief = belief_exp1, trust = trust_exp1, belief_1,
                    media_format, wave, alleg_treatment = alleg_treatment_1, partisan = partisan_1, partisan_lean = partisan_1_lean,
                    party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
    ) %>%
  rbind(
    ld4 %>% filter(alleg_treatment != "Opp. Rally") %>% 
  mutate(wave = 4) %>% 
  dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  ) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Opp. Rally") %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 5) %>% 
      dplyr::select(support, belief, trust, belief_1,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  )

#OR pooled
ld3_OR <- ld1 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 1) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness) %>% 
  rbind(
    ld2 %>% 
      mutate(media_format = "Text") %>% 
        mutate(wave = 2) %>% 
      dplyr::select(support = support_exp2,
                    media_format, wave, alleg_treatment = alleg_treatment_2, partisan = partisan_2, partisan_lean = partisan_2_lean,
                    party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
    ) %>%
  rbind(
    ld4 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
  mutate(wave = 4) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  ) %>%
  rbind(
    ld5 %>% filter(alleg_treatment != "Info. Uncertain") %>% 
      mutate(media_format = "Text") %>%
  mutate(wave = 5) %>% 
  dplyr::select(support,
                media_format, wave, alleg_treatment, partisan, partisan_lean,
                party, gender, race, age, education, income, region, media_literacy, digital_literacy, attentiveness)
  )

#Interact with co-partisan variable
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti <- iu_anti[2,]

or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti <- or_anti[2,]

iu_mod <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod <- iu_mod[2,]

or_mod <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod <- or_mod[2,]

iu_co <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co <- iu_co[2,]

or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co <- or_co[2,]

iu_anti_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti_att <- iu_anti_att[2,]

or_anti_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti_att <- or_anti_att[2,]

iu_mod_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_mod_att <- iu_mod_att[2,]

or_mod_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_mod_att <- or_mod_att[2,]

iu_co_att <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_co_att <- iu_co_att[2,]

or_co_att <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co_att <- or_co_att[2,]

co_data <- rbind(iu_co, or_co, iu_mod, or_mod, iu_anti, or_anti,
                 iu_co_att, or_co_att, iu_mod_att, or_mod_att, iu_anti_att, or_anti_att)
co_data$model <- c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan",
                   "Co-partisan Atttentive", "Co-partisan Attentive", "Independent Attentive", "Independent Attentive", "Out-partisan Attentive", "Out-partisan Attentive")
co_data$partisan <- rep(c("Co-partisan", "Co-partisan", "Independent", "Independent", "Out-partisan", "Out-partisan"), 2)
co_data$term <- rep(rep(c("Info. Uncertain", "Opp. Rally"), 3), 2)
co_data$attentive <- rep(c("Full", "Attentive Only"), each = 6)

#Figure 5
pdf(file.path(base_dir, "Figures/pooled_copartisan_coefplot_all_studies_lean.pdf"), width=7.5, height=4.5)

co_plot <- dwplot(co_data %>% arrange(partisan),
vline = geom_vline(xintercept = 0, colour = "grey60", linetype = 2),
dot_args = list(size = 3, aes(color = partisan, shape = partisan)),
whisker_args = list(aes(linetype = attentive, color = partisan)))  +
  scale_linetype_manual(name = "Sample",
                        labels = c("Full", "Attentive Only"),
                        breaks = c("Full", "Attentive Only"),
                        values = c(1,2),
                        na.translate = F) +
  scale_color_manual(name = "Partisanship", 
                   labels = c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   breaks=c("Co-partisan", "Independent", "Out-partisan") %>% rev(),
                   values = c("#F8766D", "#00BA38", "#619CFF"),
                   na.translate = F) +
 scale_shape_manual(name = "Partisanship", 
                    labels = c("Co-partisan", "Independent", "Out-partisan"), 
                    breaks=c("Co-partisan", "Independent", "Out-partisan"),
                    values = c(15, 17, 16),
                    na.translate = F) +
    xlab("\nTreatment Effect (Standardized)") + ylab("") + ggtitle("Effects on Politician Support Index by Co-partisanship") +
    xlim(-.25, .5) +
    theme_bw() + 
    theme(plot.title = element_text(face="bold"),
          legend.position = "right",
          legend.background = element_rect(colour="grey80"),
          axis.title.x = element_text(size = 11), axis.text.y = element_text(size = 9),
          legend.text = element_text(size = 10), legend.title = element_text(size = 10)
          )
co_plot
dev.off()


#Table B14
IU_fig4 <- lm(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 Regression Results",
          label="tab:fig_4",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Studies 1, 2, 4, 5", "Studies 1, 2, 4, 5")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_all_studies.tex"))

#Table B15
IU_fig4 <- lm(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)
OR_fig4 <- lm(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=2) + wave +
                         gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(IU_fig4, OR_fig4,
          se = starprep(IU_fig4, OR_fig4),
          covariate.labels=c("Info. Uncertain", "Opp. Rally", "Anti-partisan", "Co-partisan",
                             "Wave",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Info. Uncertain x Anti-partisan", "Info. Uncertain x Co-partisan",
                             "Opp. Rally x Anti-partisan", "Opp. Rally x Co-partisan",
                             "Constant"),
          dep.var.labels = "Politician Support Index",
          keep.stat = c("n","rsq"),
          title="Figure 5 Regression Results - Attentive",
          label="tab:fig_4_attentive",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
				  add.lines = list(c("Sample", "Studies 1, 2, 4, 5 Att.", "Studies 1, 2, 4, 5 Att.")),
          style="APSR",
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/fig_4_table_all_studies_attentive.tex"))


#Are the differences between co-partisans and out-partisans significant for OR?
or_co <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co[2,] #0.28 standard deviation effect for co-partisans
or_co$p.value[or_co$term=="alleg_treatmentOpp. Rally:relevel(factor(partisan_lean), ref = 3)-1"] #0.028

#With the attentive sample?
or_co <- lm_robust(data = ld3_OR %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=3) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_co[2,] #0.30 standard deviation effect for attentive co-partisans
or_co$p.value[or_co$term=="alleg_treatmentOpp. Rally:relevel(factor(partisan_lean), ref = 3)-1"] #0.159

#Effects on out-partisans
or_anti <- lm_robust(data = ld3_OR %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
or_anti[2,] #0.17 standard deviation effect for out-partisans

#Are the differences between out-partisans and others significant for IU?
iu_anti <- lm_robust(data = ld3_IU %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti$p.value[iu_anti$term=="alleg_treatmentInfo. Uncertain:relevel(factor(partisan_lean), ref = 1)0"] #0.02 compared to independents
iu_anti$p.value[iu_anti$term=="alleg_treatmentInfo. Uncertain:relevel(factor(partisan_lean), ref = 1)1"] #0.04 compared to co-partisans

#With the attentive sample?
iu_anti <- lm_robust(data = ld3_IU %>% filter(attentiveness==2) %>% filter(media_format == "Text"),
                       support ~ alleg_treatment*relevel(factor(partisan_lean), ref=1) + wave +
                        gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
iu_anti$p.value[iu_anti$term=="alleg_treatmentInfo. Uncertain:relevel(factor(partisan_lean), ref = 1)0"] #0.62 compared to independents
iu_anti$p.value[iu_anti$term=="alleg_treatmentInfo. Uncertain:relevel(factor(partisan_lean), ref = 1)1"] #0.80 compared to co-partisans

```


#####Figure 6: Impacts on Belief in Scandal
#####Figure B1: Impacts on Belief in Scandal - Attentive
```{r}
#Figure 6
mean(ld5$belief_new[ld5$alleg_treatment=="Control"])
mean(ld5$belief_new[ld5$alleg_treatment=="Info. Uncertain"])
mean(ld5$belief_new[ld5$alleg_treatment=="Opp. Rally"])
annotations <- data.frame(
  xpos = c(-Inf,-Inf,-Inf),
  ypos =  c(Inf, Inf,Inf),
  annotateText = c("Mean: 3.25","Mean: 3.05","Mean: 3.07"),
  hjustvar = c(-.03,-.03,-.03) ,
  vjustvar = c(1.1,1.1,1.1),
  alleg_treatment = c("Control", "Info. Uncertain", "Opp. Rally"))

pdf(file.path(base_dir, "Figures/belief_new_distributions.pdf"), width=8.5, height=4.5)
ld5 %>% 
  count(alleg_treatment, belief_new) %>%
  group_by(alleg_treatment) %>% mutate(pct = n/sum(n)) %>% ungroup() %>%
  ggplot(aes(x = belief_new, y = pct, label = scales::percent(pct)), fill = "#474747") +
  geom_col(position = "dodge", width=.6, color = "#474747") +
  geom_text(position = position_dodge(width = 0.9), vjust = -0.5) +
  geom_text(data=annotations,aes(x=xpos,y=ypos,hjust=hjustvar,vjust=vjustvar,label=annotateText), inherit.aes=F, size=3.5) +
  facet_wrap(~alleg_treatment) +
  theme_bw() +
  theme(legend.title = element_blank(),
        panel.grid = element_blank()) +
  xlab("Belief in Scandal") + ylab("Percentage of Respondents") +
  scale_y_continuous(labels = scales::percent) +
  geom_vline(data = ld5 %>%
               group_by(alleg_treatment) %>%
               summarize(mean = mean(belief_new, na.rm=T)) %>%
               pivot_longer(-alleg_treatment) %>%
               mutate(name = as.factor(name)),
             aes(xintercept = value), linetype=2)
dev.off()


#Figure B1
mean(ld5$belief_new[ld5$alleg_treatment=="Control" & ld5$attentiveness==2])
mean(ld5$belief_new[ld5$alleg_treatment=="Info. Uncertain" & ld5$attentiveness==2])
mean(ld5$belief_new[ld5$alleg_treatment=="Opp. Rally" & ld5$attentiveness==2])
annotations <- data.frame(
  xpos = c(-Inf,-Inf,-Inf),
  ypos =  c(Inf, Inf,Inf),
  annotateText = c("Mean: 3.21","Mean: 2.94","Mean: 2.97"),
  hjustvar = c(-.03,-.03,-.03) ,
  vjustvar = c(1.1,1.1,1.1),
  alleg_treatment = c("Control", "Info. Uncertain", "Opp. Rally"))

pdf(file.path(base_dir, "Figures/belief_new_distributions_attentive.pdf"), width=8.5, height=4.5)
ld5 %>% filter(attentiveness==2) %>%
  count(alleg_treatment, belief_new) %>%
  group_by(alleg_treatment) %>% mutate(pct = n/sum(n)) %>% ungroup() %>%
  ggplot(aes(x = belief_new, y = pct, label = scales::percent(pct)), fill = "#474747") +
  geom_col(position = "dodge", width=.6, color = "#474747") +
  geom_text(position = position_dodge(width = 0.9), vjust = -0.5) +
  geom_text(data=annotations,aes(x=xpos,y=ypos,hjust=hjustvar,vjust=vjustvar,label=annotateText), inherit.aes=F, size=3.5) +
  facet_wrap(~alleg_treatment) +
  theme_bw() +
  theme(legend.title = element_blank(),
        panel.grid = element_blank()) +
  xlab("Belief in Scandal") + ylab("Percentage of Respondents") +
  scale_y_continuous(labels = scales::percent) +
  geom_vline(data = ld5 %>%
               group_by(alleg_treatment) %>%
               summarize(mean = mean(belief_new, na.rm=T)) %>%
               pivot_longer(-alleg_treatment) %>%
               mutate(name = as.factor(name)),
             aes(xintercept = value), linetype=2)
dev.off()


#Did treatment significantly reduce belief in scandal?
ld5$belief_new_std <- scale(ld5$belief_new)
mechs_belief <- lm_robust(data = ld5, 
                   belief_new_std ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
#IU
mechs_belief[2,] #-0.15 standard deviations, p-value = 0.001
#OR
mechs_belief[3,] #-0.14 standard deviations, p-value = 0.002

mechs_belief_att <- lm_robust(data = ld5 %>% filter(attentiveness==2), 
                   belief_new_std ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
#IU
mechs_belief_att[2,] #-0.23 standard deviations, p-value = 0.003
#OR
mechs_belief_att[3,] #-0.21 standard deviations, p-value = 0.006


#Is belief in the allegation correlated with belief in scandal?
cor(ld5$belief_new[ld5$alleg_treatment!="Control"], ld5$belief_alleg[ld5$alleg_treatment!="Control"]) #-0.22

cor(ld5$belief_new[ld5$alleg_treatment!="Control" & ld5$attentiveness==2], ld5$belief_alleg[ld5$alleg_treatment!="Control" & ld5$attentiveness==2]) #-0.40 for attentive


#Is belief in the allegation correlated with support?
cor(ld5$belief_alleg[ld5$alleg_treatment!="Control"], ld5$support[ld5$alleg_treatment!="Control"]) #0.39

cor(ld5$belief_alleg[ld5$alleg_treatment!="Control" & ld5$attentiveness==2], ld5$support[ld5$alleg_treatment!="Control" & ld5$attentiveness==2]) #0.43 for attentive


#Did the respondents find the scandals embarrassing?
ld5 %>% group_by(politician) %>% summarize(avg_embarrassing = mean(reputation))
length(which(ld5$reputation>=4))/nrow(ld5)*100 #67% agreed with the statement that the scandal was damaging to the politician's reputation


#Is belief in the scandal correlated with whether respondents find the scandals embarrassing?
cor(ld5$belief_new[ld5$alleg_treatment=="Control"], ld5$reputation[ld5$alleg_treatment=="Control"]) #0.14

cor(ld5$belief_new[ld5$alleg_treatment=="Control" & ld5$attentiveness==2], ld5$reputation[ld5$alleg_treatment=="Control" & ld5$attentiveness==2]) #0.06 for attentive

```


#####Table 2: Impacts on Trust in Media
#####Table B16: Table 2 Full Regression Results
#####Table B22: Table 2 Full Regression Results - Attentive
```{r}
#Table 2
ld2_trust <- ld2
ld2_trust$trust <- ld2_trust$trust_exp1
ld2_trust$alleg_treatment <- ld2_trust$alleg_treatment_1

study_1_trust <- lm(data = ld1 %>% filter(media_format == "Text"), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_2_trust <- lm(data = ld2_trust, 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_4_trust <- lm(data = ld4 %>% filter(media_format == "Text"), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_5_trust <- lm(data = ld5, 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)


#Create regression table
stargazer(study_1_trust, study_2_trust, study_4_trust, study_5_trust, 
          se = starprep(study_1_trust, study_2_trust, study_4_trust, study_5_trust),
          keep = c("alleg_treatmentInfo. Uncertain", "alleg_treatmentOpp. Rally"),
          covariate.labels=c("Info. Uncertain", "Opp. Rally"),
          dep.var.labels.include = F,
				  column.labels = c("Trust in Media Index"),
          column.separate = c(4),
          keep.stat = c("n","rsq"),
          title="Impacts on Trust in Media",
          label="tab:trust_table",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 1 Text", "Study 2", "Study 4 Text", "Study 5")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/trust_table.tex"))

#Table B16
stargazer(study_1_trust, study_2_trust, study_4_trust, study_5_trust,
          se = starprep(study_1_trust, study_2_trust, study_4_trust, study_5_trust),
          omit = c("Fact Check"),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Trust in Media Index"),
          column.separate = c(4),
          keep.stat = c("n","rsq"),
          title="Table 2 Full Regression Results",
          label="tab:table_1",
          font.size = "scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 1 Text", "Study 2", "Study 4 Text", "Study 5")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/tab_1_full_table.tex"))

#Table B22
study_1_trust <- lm(data = ld1 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_2_trust <- lm(data = ld2_trust %>% filter(attentiveness==2), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_4_trust <- lm(data = ld4 %>% filter(attentiveness==2) %>% filter(media_format == "Text"), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

study_5_trust <- lm(data = ld5 %>% filter(attentiveness==2), 
                   trust ~ alleg_treatment +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(study_1_trust, study_2_trust, study_4_trust, study_5_trust,
          se = starprep(study_1_trust, study_2_trust, study_4_trust, study_5_trust),
          omit = c("Fact Check"),
          covariate.labels=c("Info. Uncertain", "Opp. Rally",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels.include = F,
          column.labels = c("Trust in Media Index"),
          column.separate = c(4),
          keep.stat = c("n","rsq"),
          title="Table 2 Full Regression Results - Attentive",
          label="tab:table_1_attentive",
          font.size = "scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
				  notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 1 Att. Text", "Study 2 Att.", "Study 4 Att. Text", "Study 5 Att.")),
          header=F,
          type="latex",
          out=file.path(base_dir, "Tables/tab_1_full_table_attentive.tex"))


#Are effects significant for Study 2?
IU_trust <- lm_robust(data = ld2, 
                   trust_exp1 ~ alleg_treatment_1 +
                     party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
IU_trust$p.value[IU_trust$term=="alleg_treatment_1Info. Uncertain"] #0.075


#What was the level of trust in media?
ld1 %>% filter(alleg_treatment=="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld1$alleg_treatment=="Control"))*100) #28\%
ld2 %>% filter(alleg_treatment_1=="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld2$alleg_treatment_1=="Control"))*100) #33\%
ld4 %>% filter(alleg_treatment=="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld4$alleg_treatment=="Control"))*100) #23\%
ld5 %>% filter(alleg_treatment=="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld5$alleg_treatment=="Control"))*100) #23\%

ld1 %>% filter(alleg_treatment!="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld1$alleg_treatment!="Control"))*100) #27\%
ld2 %>% filter(alleg_treatment_1!="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld2$alleg_treatment_1!="Control"))*100) #29\%
ld4 %>% filter(alleg_treatment!="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld4$alleg_treatment!="Control"))*100) #21\%
ld5 %>% filter(alleg_treatment!="Control") %>% summarize(length(which(trust_1>=4))/length(which(ld5$alleg_treatment!="Control"))*100) #21\%
        
   
```


#####Figure 7: Treatment Wordings for Alternative Politician Responses
No code required, includes the exact wordings of the apology and simple denial treatments


#####Table 3: Allegations of Misinformation Versus Apologies
#####Table B17: Table 3 Full Regression Results
#####Table B23: Table 3 Full Regression Results - Attentive
```{r table 2}
#IU versus apology
ld3$alleg_treatment_3 <- factor(ld3$alleg_treatment, levels = c("Apology","Info. Uncertain", "Simple Denial"))

#Do the allegation treatments affect politician support?
hyp_1_combined_support <- lm(data = ld3, 
                             support ~ alleg_treatment_3 +
                               party + gender + race + age + education + income + region + media_literacy + digital_literacy)
hyp_1_combined_support %>% summary


#Do the allegation treatments affect belief in the story?
hyp_1_combined_belief <- lm(data = ld3, 
                             belief ~ alleg_treatment_3 +
                              party + gender + race + age + education + income + region + media_literacy + digital_literacy)
hyp_1_combined_belief %>% summary


#Do the allegation treatments affect trust in media?
hyp_1_combined_trust <- lm(data = ld3, 
                             trust ~ alleg_treatment_3 +
                             party + gender + race + age + education + income + region + media_literacy + digital_literacy)
hyp_1_combined_trust %>% summary

#Table 3
stargazer(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust, 
          se = starprep(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust),
          keep = c("alleg_treatment_3Info. Uncertain", "alleg_treatment_3Simple Denial"),
          covariate.labels=c("Info. Uncertain", "Simple Denial"),
          dep.var.labels = c("Support Index", "Belief Index", "Trust Index"),
          keep.stat = c("n","rsq"),
          title="Allegations of Misinformation and Simple Denials versus Apologies",
          label="tab:combined",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 3", "Study 3", "Study 3")),
          header=F,
          type="latex",
				  out=file.path(base_dir, "Tables/study_3_table.tex"))

#Table B17
stargazer(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust, 
          se = starprep(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust),
          covariate.labels=c("Info. Uncertain", "Simple Denial",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = c("Support Index", "Belief Index", "Trust Index"),
          keep.stat = c("n","rsq"),
          title="Table 3 Full Regression Results",
          label="tab:table_2",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 3", "Study 3", "Study 3")),
          header=F,
          type="latex",
				  out=file.path(base_dir, "Tables/tab_2_full_table.tex"))

#Table B23
hyp_1_combined_support <- lm(data = ld3 %>% filter(attentiveness==2), 
                             support ~ alleg_treatment_3 +
                               party + gender + race + age + education + income + region + media_literacy + digital_literacy)
hyp_1_combined_belief <- lm(data = ld3 %>% filter(attentiveness==2), 
                             belief ~ alleg_treatment_3 +
                              party + gender + race + age + education + income + region + media_literacy + digital_literacy)
hyp_1_combined_trust <- lm(data = ld3 %>% filter(attentiveness==2), 
                             trust ~ alleg_treatment_3 +
                             party + gender + race + age + education + income + region + media_literacy + digital_literacy)

stargazer(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust, 
          se = starprep(hyp_1_combined_support, hyp_1_combined_belief, hyp_1_combined_trust),
          covariate.labels=c("Info. Uncertain", "Simple Denial",
                             "Strong Democrat", "Democrat", "Lean Democrat", 
                             "Lean Republican", "Republican",
                             "Strong Republican",
                             "Female",
                             "Black", "Hispanic", "Asian", "Other Race",
                             "Millennial", "Gen X", "Boomer", "Silent Gen.",
                             "Some College", "Bachelor's Degree", "Graduate Degree",
                             "Low Income", "High Income",
                             "Midwest", "South", "West",
                             "Media Literacy",
                             "Digital Literacy",
                             "Constant"),
          dep.var.labels = c("Support Index", "Belief Index", "Trust Index"),
          keep.stat = c("n","rsq"),
          title="Table 3 Full Regression Results - Attentive",
          label="tab:table_2_attentive",
          font.size="scriptsize",
          star.char = c("+","*","**","***"), 
				  star.cutoffs = c(0.1,0.05,0.01,0.001), 
				  notes = c("$^{+}$p $<$ .1; $^{*}$p $<$ .05; $^{**}$p $<$ .01; $^{***}$p $<$ .001"),
          notes.append = F,
          style="APSR",
				  add.lines = list(c("Sample", "Study 3 Att.", "Study 3 Att.", "Study 3 Att.")),
          header=F,
          type="latex",
				  out=file.path(base_dir, "Tables/tab_2_full_table_attentive.tex"))


#Allegations of misinformation versus denials
hyp_1_combined_support <- lm_robust(data = ld3, 
                             support ~ relevel(alleg_treatment_3, ref="Simple Denial") +
                              party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
hyp_1_combined_support$estimate[3] #0.06
hyp_1_combined_support$p.value[3] #0.167
hyp_1_combined_belief <- lm_robust(data = ld3, 
                             belief ~ relevel(alleg_treatment_3, ref="Simple Denial") +
                              party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
hyp_1_combined_belief$estimate[3] #-0.08
hyp_1_combined_belief$p.value[3] #0.054
hyp_1_combined_trust <- lm_robust(data = ld3, 
                             trust ~ relevel(alleg_treatment_3, ref="Simple Denial") +
                             party + gender + race + age + education + income + region + media_literacy + digital_literacy) %>% tidy
hyp_1_combined_trust$estimate[3] #-0.04
hyp_1_combined_trust$p.value[3] #0.344

#Trust in media by treatment groups
ld3 %>% group_by(alleg_treatment) %>% summarize(
  trust_mean <- mean(trust_1)
)
table(ld3$alleg_treatment, ld3$trust_1) %>% prop.table(1)

```

